
function datebase(fn,url){
    var xml =new XMLHttpRequest();
    // debugger;
    // console.log(0,xml.readyState)
    // console.log(xml);
    xml.open("get",url,true);
    // console.log(1,xml.readyState)
    // console.log(xml);

    xml.send();
    // console.log(2,xml.readyState)
    // console.log(xml);
    xml.onreadystatechange = function(){
        // console.log(3,xml.readyState)
        // console.log(xml);
        if(this.status === 200){
            if(this.readyState === 4){
                // console.log(this.responseText)
                fn(this.responseText);
                // console.log(4,xml.readyState)
                // console.log(xml);

            }
        }
    }

}
datebase(function(text){
    var content =JSON.parse(text);
    // console.log(content);
    var dId= location.search.substr(1);
    
    for (let index = 0; index < content.length; index++) {
        let el = content[index];
        if(el.id==dId){
            var aIndex=index;
        }
        // console.log(nId);
    }
    var ah3 = document.getElementsByTagName("h3")[0];
    // console.log(content)
    ah3.innerText=content[aIndex].blogName;
    var ah4 = document.getElementsByTagName("h4")[0];
    ah4.innerText=content[aIndex].blogTime;
    var aul = document.getElementById("blogText");
    // console.log(content[aIndex].blogText);
    for (let index = 0; index <content[aIndex].blogText.length; index++) {
        var oLi = document.createElement("li");
        aul.appendChild(oLi);
        oLi.innerHTML=content[aIndex].blogText[index]
    }
    var oBlogImg = document.getElementById("blogImg"); 
    if(content[aIndex].blogImgNum){
        for (let index = 0; index < content[aIndex].blogImgNum.length; index++) {

            var oimg = document.createElement("img");
            oBlogImg.appendChild(oimg);
            oimg.setAttribute("src","./img/dayBlog"+content[aIndex].blogImgNum[index]+".jpg");
    }
    }



    var oskipUp = document.getElementsByClassName("skipUp")[0];
    var oskipDown = document.getElementsByClassName("skipDown")[0];
    var oiUp = oskipUp.getElementsByTagName("i")[0];
    var oiDown = oskipDown.getElementsByTagName("i")[0];
    if(aIndex>0){
        oiUp.innerText=content[aIndex-1].blogName; 
        oskipUp.setAttribute("href","./dayBlog.html?"+content[aIndex-1].id);
    }else{
        oiUp.innerText="没有上一张了~"
        oskipUp.setAttribute("href","javascript:;")
    }
    if(aIndex+1<content.length){
        oiDown.innerText=content[aIndex+1].blogName; 
        oskipDown.setAttribute("href","./dayBlog.html?"+content[aIndex+1].id);
    }else{
        oiDown.innerText="没有下一张了~"
        oskipDown.setAttribute("href","javascript:;")
    }
}
,getUrl());

function getUrl(){
    var arrUrl = localStorage.getItem("arrUrl");
    var iii = "./datebase/"+arrUrl+".json"
    // console.log(iii);
    return "./datebase/"+arrUrl+".json"
}




